import {
  fakeStatisticChartData,
  getProStaffList,
  getProStaffDetail,
  getProOrganList,
  getProOrganDetail,
  getProPoliceList,
  getProPoliceDetail,
  getProFormationList,
  getProFormationDetail,
  getProPositionList,
  getProPositionDetail,
  getPoliceStaticList,
  getPoliceStaticDetail,
  getPoliceRankTreeByParentid,
  getDutyLevelTreeByParentid,
  getWorkTreeByParentid,
  getChangeTypeTreeByParentid
} from '@/services/api';


export default {
  namespace: 'statisticchart',

  state: {
    staffListData: {
        list: [],
        pagination: {},
    },
    staffDetialData: {
        list: [],
        pagination: {},
    },
    organListData: {
        list: [],
        pagination: {},
    },
    organDetialData: {
        list: [],
        pagination: {},
    },
    policeListData: {
        list: [],
        pagination: {},
    },
    policeDetialData: {
        list: [],
        pagination: {},
    },
    formationListData: {
        list: [],
        pagination: {},
    },
    formationDetialData: {
        list: [],
        pagination: {},
    },
    positionListData: {
        list: [],
        pagination: {},
    },
    positionDetialData: {
        list: [],
        pagination: {},
    },
    policeStaticListData: {
        list: [],
        pagination: {},
    },
    policeStaticDetailData: {
        list: [],
        pagination: {},
    },
    selectPoliceRankTree: {
    	list:[],
    },
    selectDutyLevelTree: {
    	list:[],
    },
    selectWorkTree: {
    	list:[],
    },
    selectChangeTypeTree: {
    	list:[],
    },

    visitData: [],
    visitData2: [],
    salesData: [],
    searchData: [],
    offlineData: [],
    offlineChartData: [],
    salesTypeData: [],
    salesTypeDataOnline: [],
    salesTypeDataOffline: [],
    radarData: [],
    loading: false,

    staffInfoDataByArea: [],
  	staffInfoDataByType: [],
  	staffInfoDataByPoliticsFace: [],
  	staffInfoDataByPostType: [],
  	staffInfoDataByStaffNation: [],

    organInfoData:[],
    organInfoDataByType: [],
  	organInfoDataByLevel: [],
  	policeDataByPoliceRank: [],
  	policeDataByDutyLevel: [],
    policeSpreadData:[],
  	formationData:[],
  	positionData:[]
  },

  effects: {
    *fetch(_, { call, put }) {
      const response = yield call(fakeStatisticChartData);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchSalesData(_, { call, put }) {
      const response = yield call(fakeChartData);
      yield put({
        type: 'save',
        payload: {
          salesData: response.salesData,
        },
      });
    },
    *get_prostaff_list({ payload, callback }, { call, put }) {
        const response = yield call(getProStaffList, payload);
        yield put({
            type: 'getProStaffList',
            payload: response,
        });

        if (callback) callback();
    },
    *get_prostaff_detail({ payload, callback }, { call, put }) {
        const response = yield call(getProStaffDetail, payload);
        yield put({
            type: 'getProStaffDetail',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_proorgan_list({ payload, callback }, { call, put }) {
        const response = yield call(getProOrganList, payload);
        yield put({
            type: 'getProOrganList',
            payload: response,
        });

        if (callback) callback();
    },
    *get_proorgan_detail({ payload, callback }, { call, put }) {
        const response = yield call(getProOrganDetail, payload);
        yield put({
            type: 'getProOrganDetail',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_propolice_list({ payload, callback }, { call, put }) {
        const response = yield call(getProPoliceList, payload);
        yield put({
            type: 'getProPoliceList',
            payload: response,
        });

        if (callback) callback();
    },
    *get_propolice_detail({ payload, callback }, { call, put }) {
        const response = yield call(getProPoliceDetail, payload);
        yield put({
            type: 'getProPoliceDetail',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_proformation_list({ payload, callback }, { call, put }) {
        const response = yield call(getProFormationList, payload);
        yield put({
            type: 'getProFormationList',
            payload: response,
        });

        if (callback) callback();
    },
    *get_proformation_detail({ payload, callback }, { call, put }) {
        const response = yield call(getProFormationDetail, payload);
        yield put({
            type: 'getProFormationDetail',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_proposition_list({ payload, callback }, { call, put }) {
        const response = yield call(getProPositionList, payload);
        yield put({
            type: 'getProPositionList',
            payload: response,
        });

        if (callback) callback();
    },
    *get_proposition_detail({ payload, callback }, { call, put }) {
        const response = yield call(getProPositionDetail, payload);
        yield put({
            type: 'getProPositionDetail',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_policestatic_list({ payload, callback }, { call, put }) {
        const response = yield call(getPoliceStaticList, payload);
        yield put({
            type: 'getPoliceStaticList',
            payload: response,
        });

        if (callback) callback();
    },
    *get_policestatic_detail({ payload, callback }, { call, put }) {
        const response = yield call(getPoliceStaticDetail, payload);
        yield put({
            type: 'getPoliceStaticDetail',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_police_ranktree_by_parentid({ payload, callback }, { call, put }) {
        const response = yield call(getPoliceRankTreeByParentid, payload);
        yield put({
            type: 'getPoliceRankTreeByParentid',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_duty_level_tree_by_parentid({ payload, callback }, { call, put }) {
        const response = yield call(getDutyLevelTreeByParentid, payload);
        yield put({
            type: 'getDutyLevelTreeByParentid',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_worktree_by_parentid({ payload, callback }, { call, put }) {
        const response = yield call(getWorkTreeByParentid, payload);
        yield put({
            type: 'getWorkTreeByParentid',
            payload: response,
        });

        if (callback) callback(response);
    },
    *get_changetypetree_by_parentid({ payload, callback }, { call, put }) {
        const response = yield call(getChangeTypeTreeByParentid, payload);
        yield put({
            type: 'getChangeTypeTreeByParentid',
            payload: response,
        });

        if (callback) callback(response);
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    getProStaffList(state, action) {
        return {
            ...state,
            staffListData: action.payload,
        };
    },
    getProStaffDetail(state, action) {
        return {
            ...state,
            staffDetialData: action.payload,
        };
    },
    getProOrganList(state, action) {
        return {
            ...state,
            organListData: action.payload,
        };
    },
    getProOrganDetail(state, action) {
        return {
            ...state,
            organDetialData: action.payload,
        };
    },
    getProPoliceList(state, action) {
        return {
            ...state,
            policeListData: action.payload,
        };
    },
    getProPoliceDetail(state, action) {
        return {
            ...state,
            policeDetialData: action.payload,
        };
    },
    getProFormationList(state, action) {
        return {
            ...state,
            formationListData: action.payload,
        };
    },
    getProFormationDetail(state, action) {
        return {
            ...state,
            formationDetialData: action.payload,
        };
    },
    getProPositionList(state, action) {
        return {
            ...state,
            positionListData: action.payload,
        };
    },
    getProPositionDetail(state, action) {
        return {
            ...state,
            positionDetialData: action.payload,
        };
    },
    getPoliceStaticList(state, action) {
        return {
            ...state,
            policeStaticListData: action.payload,
        };
    },
    getPoliceStaticDetail(state, action) {
        return {
            ...state,
            policeStaticDetailData: action.payload,
        };
    },
    getPoliceRankTreeByParentid(state, action) {
        return {
            ...state,
            selectPoliceRankTree: action.payload,
        };
    },
    getDutyLevelTreeByParentid(state, action) {
        return {
            ...state,
            selectDutyLevelTree: action.payload,
        };
    },
    getWorkTreeByParentid(state, action) {
        return {
            ...state,
            selectWorkTree: action.payload,
        };
    },
    getChangeTypeTreeByParentid(state, action) {
        return {
            ...state,
            selectChangeTypeTree: action.payload,
        };
    },
    clear() {
      return {
        visitData: [],
        visitData2: [],
        salesData: [],
        searchData: [],
        offlineData: [],
        offlineChartData: [],
        salesTypeData: [],
        salesTypeDataOnline: [],
        salesTypeDataOffline: [],
        radarData: [],
      };
    },
  },
};
